package com.example.workflow.controller;

import com.example.workflow.bo.Expense;
import com.example.workflow.bo.ExpenseAddBo;
import com.example.workflow.bo.ExpenseQueryBo;
import com.example.workflow.service.ExpenseService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ExpenseController {
    @Autowired
    private ExpenseService expenseService;

    @PostMapping("/submit")
    public String submit(@RequestBody ExpenseAddBo expenseAddBo) {
        log.info("请假审批提交+"+expenseAddBo);
        Expense expense = new Expense();
        BeanUtils.copyProperties(expenseAddBo, expense);
        expense.setStatus(1);
        expenseService.submit(expense);
        return "Submit Expense Success";
    }

    @PostMapping("/approval")
    public String approval(@RequestBody ExpenseQueryBo expenseQueryBo) {
        log.info("请假审批审核+" + expenseQueryBo);
        Expense expense = new Expense();
        BeanUtils.copyProperties(expenseQueryBo, expense);
        expenseService.approval(expense, expenseQueryBo);
        return "Approval Expense Success";
    }
}
